package cn.m3a1.control.admin;

import cn.m3a1.bean.Msg;
import cn.m3a1.bean.SysLog;
import cn.m3a1.service.admin.AdminSysService;
import cn.m3a1.util.GlobalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author wyj
 * @date 2019/7/8
 * @time 上午9:03
 */
@Controller
@RequestMapping("/admin")
public class AdminSysController {
    @Autowired
    AdminSysService adminSysService;

    /**
     *
     * @param modelMap
     * @return
     */
    @RequestMapping("/sysHome")
    public String sysHome(String sys,ModelMap modelMap){
        List<SysLog> allSys;
        if (GlobalUtils.isEmpty(sys)){
           allSys = adminSysService.getAllSys();
        }else{
            System.out.println(sys);
             allSys = adminSysService.getAllSys(sys);
        }

        modelMap.put("members",allSys);
        return "Admin/AdminSys";
    }

    /**
     * 删除日志
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/sysDel")
    public Msg delSys(int id){
        Boolean b = adminSysService.delSys(id);
        if (b){
            return Msg.success();
        }
        return  Msg.fail();
    }
}
